home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / ubiquity / migration-assistant / ma-ask < prev    next >
Text File  |  2009-04-07  |  8KB  |  179 lines

  1. #!/bin/sh
  2.  
  3. # TODO: Incorporate capb backup.
  4.  
  5. set -e
  6. . /usr/share/debconf/confmodule
  7. . /usr/share/migration-assistant/ma-script-utils
  8.  
  9. if [ -z "$1" ]; then
  10.     mapath="/usr/bin"
  11. else
  12.     mapath="$1"
  13. fi
  14.  
  15. OLDIFS="$IFS"
  16. NEWLINE='
  17. '
  18.  
  19. IFS="$NEWLINE"
  20. tmp=
  21. for line in `os-prober`;
  22. do
  23.     dist=$(LC_ALL=C expr match "$line" '.*:\(.*\):.*:.*')
  24.     location=${line%%:*}
  25.     if [ -z "$tmp" ]; then
  26.         tmp="$dist ($location)"
  27.     else
  28.         tmp="$tmp, $dist ($location)"
  29.     fi
  30. done
  31. IFS="$OLDIFS"
  32.  
  33. db_subst migration-assistant/partitions choices "$tmp"
  34. db_input high migration-assistant/partitions || true
  35. db_go || exit 10
  36.  
  37. db_get migration-assistant/partitions || RET=
  38. IFS="$NEWLINE"
  39. selection=`echo "$RET" | sed -e 's/, /\n/g'`
  40. for choice in $selection; do # Microsoft Windows XP Professional (/dev/hda1)
  41.     IFS="$OLDIFS"
  42.     location=$(LC_ALL=C expr "$choice" : '.*(\(.*\))$') # /dev/hda1
  43.     IFS="$NEWLINE"
  44.     for line in `os-prober`; do
  45.         IFS="$OLDIFS"
  46.         loc="${line%%:*}"
  47.         if [ "$location" != "$loc" ]; then
  48.             continue
  49.         fi
  50.         log "setting ostype from: '$line'"
  51.         set_os_type "$line" || continue
  52.         log "got ostype of: '$ostype', mountpoint is: '$mountpoint'"
  53.  
  54.         path="${loc#*/*/}" # hda1 or discs/disc0/part1
  55.         mount_os "$ostype" "$loc"
  56.         db_register migration-assistant/users migration-assistant/$path/users
  57.         db_subst migration-assistant/$path/users user-choices \
  58.             "$($mapath/ma-search-users "$ostype" "$mountpoint" 2>>/var/log/syslog)"
  59.         db_subst migration-assistant/$path/users os-type "$choice"
  60.  
  61.         db_input high migration-assistant/$path/users || true
  62.         db_go || exit 10
  63.  
  64.         db_get migration-assistant/$path/users || RET=
  65.         
  66.         user_selection=`echo "$RET" | sed -e 's/, /\n/g'`
  67.         IFS="$NEWLINE"
  68.         for usr in $user_selection; do
  69.             IFS="$OLDIFS"
  70.             itemsret=$($mapath/ma-search-items --path="$mountpoint" --ostype="$ostype" --user="$usr" 2>>/var/log/syslog) || \
  71.                 (itemsret=; error "ma-search-items exited with an error for $usr.")
  72.             # FIXME: We should figure out if there are any items for each user
  73.             # before asking to import from the user.  Likewise, we should
  74.             # figure out if there are any users to import before asking to
  75.             # import from a partition.
  76.             if [ -z "$itemsret" ]; then
  77.                 continue
  78.             fi
  79.             formatted_user=`echo "$usr" | sed -e 's/ /+/g'`
  80.             db_register migration-assistant/items migration-assistant/$path/$formatted_user/items
  81.             db_subst migration-assistant/$path/$formatted_user/items choices "$itemsret"
  82.             db_subst migration-assistant/$path/$formatted_user/items user "$usr"
  83.  
  84.             # migration-assistant/discs/disc0/part1/Evan/items
  85.             db_input high migration-assistant/$path/$formatted_user/items || true
  86.             db_go || exit 10
  87.  
  88.             db_register migration-assistant/user migration-assistant/$path/$formatted_user/user
  89.             # This prevents m-a from working right. change to choices
  90.             #db_set migration-assistant/$path/$formatted_user/user "$(echo "$usr" | tr '[A-Z]' '[a-z]')"
  91.             db_subst migration-assistant/$path/$formatted_user/user old-user "$usr"
  92.  
  93.             while :; do
  94.                 db_input high migration-assistant/$path/$formatted_user/user || true
  95.                 db_go || exit 10
  96.                 
  97.                 db_get migration-assistant/$path/$formatted_user/user || RET=
  98.                 new_user="$RET"
  99.                 
  100.                 if ! LC_ALL=C expr "$new_user" : '[a-z][-a-z0-9]*$' >/dev/null; then
  101.                     db_fset migration-assistant/$path/$formatted_user/user seen false
  102.                     db_fset migration-assistant/username-bad seen false
  103.                     db_subst migration-assistant/username-bad user "$new_user"
  104.                     db_input critical migration-assistant/username-bad
  105.                     continue
  106.                 fi
  107.                 
  108.                 # TODO: Either copy this or depend on user-setup.
  109.                 if grep -v '^#' /usr/lib/user-setup/reserved-usernames | \
  110.                    grep -q "^$new_user\$"; then
  111.                     db_fset migration-assistant/$path/$formatted_user/user seen false
  112.                     db_fset migration-assistant/username-reserved seen false
  113.                     db_subst migration-assistant/username-reserved user "$new_user"
  114.                     db_input critical migration-assistant/username-reserved
  115.                     continue
  116.                 fi
  117.                 break
  118.             done
  119.  
  120.             # Only ask if the user doesn't match the one seeded for user-setup.
  121.             db_get passwd/username || RET=
  122.             if [ "$new_user" = "$RET" ]; then
  123.                 continue
  124.             fi
  125.  
  126.             # Password
  127.             db_register migration-assistant/password migration-assistant/new-user/$new_user/password
  128.             db_subst migration-assistant/new-user/$new_user/password user "$new_user"
  129.  
  130.             db_register migration-assistant/password-again migration-assistant/new-user/$new_user/password-again
  131.             db_subst migration-assistant/new-user/$new_user/password-again user "$new_user"
  132.  
  133.             while :; do
  134.                 db_input high migration-assistant/new-user/$new_user/password || true
  135.                 db_go || exit 10
  136.                 db_get migration-assistant/new-user/$new_user/password || RET=
  137.                 pass=$RET
  138.  
  139.                 db_input high migration-assistant/new-user/$new_user/password-again || true
  140.                 db_go || exit 10
  141.                 db_get migration-assistant/new-user/$new_user/password-again || RET=
  142.                 pass2=$RET
  143.                 
  144.                 if [ -z "$pass2" ] || [ -z "$pass" ]; then
  145.                     db_set migration-assistant/new-user/$new_user/password ""
  146.                     db_set migration-assistant/new-user/$new_user/password-again ""
  147.                     db_fset migration-assistant/password-empty seen "false"
  148.                     db_input high migration-assistant/password-empty || true
  149.                     db_fset migration-assistant/new-user/$new_user/password seen "false"
  150.                     db_fset migration-assistant/new-user/$new_user/password-again seen "false"
  151.                     db_go || true
  152.                     continue
  153.                 fi
  154.  
  155.                 if [ "$pass2" = "$pass" ]; then
  156.                     break
  157.                 else
  158.                     db_set migration-assistant/new-user/$new_user/password ""
  159.                     db_set migration-assistant/new-user/$new_user/password-again ""
  160.                     db_fset migration-assistant/password-mismatch seen "false"
  161.                     db_input high migration-assistant/password-mismatch || true
  162.                     db_fset migration-assistant/new-user/$new_user/password seen "false"
  163.                     db_fset migration-assistant/new-user/$new_user/password-again seen "false"
  164.                     db_go || true
  165.                 fi
  166.             done
  167.  
  168.             # Full Name
  169.             db_register migration-assistant/fullname migration-assistant/new-user/$new_user/fullname
  170.             db_subst migration-assistant/new-user/$new_user/fullname user "$new_user"
  171.             db_input high migration-assistant/new-user/$new_user/fullname || true
  172.             db_go || exit 10
  173.         done
  174.         IFS="$OLDIFS"
  175.         unmount_os
  176.     done
  177. done
  178. # vim:ai:et:sts=4:tw=80:sw=4:
  179.